<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<style type="text/css">
#categoryType {
	width: 130px;
}
</style>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="">
			<div style="margin-left: 10px;">
				<label for="jobcode">参数类别:</label> 
				<select id="categoryType">
		        	
		        </select>
		        <input type="text" style="width: 120px; height: 28px;" class="ui-input"
					name="tradeType" id="categoryTypeInput">
			</div>
			<br><br>
			<div style="margin-left: 10px;">
				<label for="jobcode">参数编码:</label> 
				<input type="text" style="width: 120px; height: 28px;" class="ui-input"
					name="tradeCode" id="categoryCode">
			</div>
			<br><br>
			<div style="margin-left: 10px;">
				<label for="jobcode">参数名称:</label> 
				<input type="text" style="width: 120px; height: 28px;" class="ui-input"
					name="tradename" id="categoryName">
			</div>
		</form>
	</div>

	<script type="text/javascript">
		var api = frameElement.api;
		var operate = api.data.operate;
		var rowid = api.data.rowid;
		var rowdata = api.data.rowdata;
		var CallBack = api.data.callback;
		$(function(){
			initPopBtns();
			initCategoryType();
			if(operate=="add"){
				$("#categoryType").show();
			}
			if(operate=="edit"){
				//alert(rowdata.id);
				//$("#categoryType option[value='"+rowdata.typeid+"']").attr("selected","selected");
				//$("#categoryType").attr("disabled","disabled").css("background-color","#EEEEEE;");
				$("#categoryTypeInput").show();
				$("#categoryTypeInput").val(rowdata.typeid);
				$("#categoryCode").val(rowdata.code);
				$("#categoryName").val(rowdata.name);
			}
		})
		
		function initCategoryType() {
			$("#categoryType").hide();
			$("#categoryTypeInput").hide();
			$.ajax({
				url:encodeURI("categoryType/list"),
				type:"POST",
				success:function(data){
					$.each(data, function(index, item){
						$("#categoryType").append("<option value="+item.id+">"+item.type+"</option>");
					})
				}
			});	
		}
		
		function initPopBtns() {
			var btnname = "add" == operate ? ["保存", "关闭"] : ["确定", "取消"];
			api.button({
				id: "confirm",
				name: btnname[0],
				focus: true,
				callback: function(e) {
					var name = $("#categoryName").val();
					var code = $("#categoryCode").val();
					var type = $("#categoryType").val();
					if(operate=="add"){
						$.ajax({
							url : 'category/add',
							type : 'POST',
							dataType : "json",
							data: {
								"type":name
							},
							async : false,
							success : function(data) {
								if(data.status==200){
									parent.Public.tips({
										content: "添加参数类别成功"
									})
									CallBack();
								}else{
									parent.Public.tips({
										type:1,
										content: "添加参数类别失败:"+data.msg
									})
								}
							}
						});
					}else{
						var type = $("#categoryTypeInput").val();
						$.ajax({
							url:encodeURI("categoryDetail/edit"),
							type:"POST",
							data:{
								"id":rowid,
								"typeid":type,
								"code":code,
								"name":name
							},
							async : false,//同步,坑爹啊。。
							success:function(data){
								if(data.status==200){
									parent.Public.tips({
										content: "修改类别成功"
									})
									CallBack();
								}else{
									parent.Public.tips({
										type:1,
										content: "修改类别失败:"+data.msg
									})
								}		
							}
						});
					}
				}
			}, {
				id: "cancel",
				name: btnname[1]
			})
		}
</script>
</body>
</html>